<template>
  <div>
    <van-nav-bar
      title="我的收货地址"
      left-text="关闭"
      left-arrow
      @click-left="goback"
    >
    </van-nav-bar>
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
export default {
  name: "re_address",
  data() {
    return {
      chosenAddressId: "1",
      user_id: JSON.parse(localStorage.getItem("waimai")).user_id,
      list: [
        // {
        //   id: "1",
        //   name: "张鑫辉",
        //   tel: "18613719915",
        //   province: "河南省",
        //   city: "郑州市",
        //   county: "中原区",
        //   address: "国家863软件园-11号楼 11号楼4楼67",
        //   addressDetail: "国家863软件园-11号楼 11号楼4楼67",
        //   isDefault: true,
        //   areaCode: "410102",
        // },
      ],
    };
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    onAdd() {
      console.log("新增地址");
      this.$router.push("/addressedit");
    },
    onEdit(item) {
      this.$router.push({
        name: "addressedit",
        params: item,
      });
    },
  },
  created() {
    this.axios({
      method: "post",
      url: "http://localhost:3000/get_user_address",
      data: {
        user_id: this.user_id,
      },
    })
      .then((res) => {
        let address_data = res.data.data;
        address_data.map((item) => {
          if (item.isDefault == "true") {
            item.isDefault = true;
          } else {
            item.isDefault = false;
          }
        });
        this.list = address_data;
      })
      .catch((err) => {
        console.log(err);
      });
  },
};
</script>

<style scoped>
/deep/.van-nav-bar__text,
/deep/.van-icon {
  color: black;
}

.van-address-list__bottom {
  background-color: rgb(231, 231, 231);
}

.van-button,
/deep/.van-address-item .van-radio__icon--checked .van-icon,
.van-tag--danger {
  background-color: rgb(218, 218, 9);
  border: 1px solid rgb(218, 218, 9);
}
</style>